package com.example.text2.controller;

import com.example.text2.pojo.Article;
import com.example.text2.pojo.PageBean;
import com.example.text2.pojo.Result;
import com.example.text2.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;


   @PostMapping
    public Result add(@RequestBody @Validated Article article){
       articleService.add(article);
       return Result.success();
   }
   @GetMapping
   public Result<PageBean<Article>> findAll(
           Integer pageNum,Integer pageSize,
            @RequestParam(required = false) String categoryId,
           @RequestParam(required = false) String state){
       PageBean<Article> pb=articleService.list(pageNum,pageSize,categoryId,state);
       return Result.success(pb);
   }

}
